package io.renren.modules.sys.customer.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import io.renren.modules.sys.customer.dao.BtCustomerBaseDao;
import io.renren.modules.sys.customer.entity.BtCustomerBaseEntity;
import io.renren.modules.sys.customer.entity.BtCustomerNavbarEntity;
import io.renren.modules.sys.customer.service.BtCustomerBaseService;
import io.renren.modules.sys.customer.service.BtCustomerNavbarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.transaction.annotation.Transactional;


@Service("btCustomerBaseService")
public class BtCustomerBaseServiceImpl extends ServiceImpl<BtCustomerBaseDao, BtCustomerBaseEntity> implements BtCustomerBaseService {
    @Autowired
    private BtCustomerNavbarService btCustomerNavbarService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<BtCustomerBaseEntity> page = this.selectPage(
                new Query<BtCustomerBaseEntity>(params).getPage(),
                new EntityWrapper<BtCustomerBaseEntity>()
        );

        return new PageUtils(page);
    }
    public BtCustomerBaseEntity SelectOneByUid (Long uid){
        return this.selectOne(new EntityWrapper<BtCustomerBaseEntity>().eq("userid",uid));
    }
    @Transactional
    public void insertNew(BtCustomerBaseEntity e){
        Long newid = baseMapper.insertOneBackprimkey(e);
        List<BtCustomerNavbarEntity> savelist = new ArrayList<BtCustomerNavbarEntity>();
        BtCustomerNavbarEntity savebean = new BtCustomerNavbarEntity();
        savebean.setName("首页");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("sy");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("简介");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("jj");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("课程分类");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("1");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("kcfl");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("地区分类");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("1");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("dqfl");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("线路汇总");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("xlhz");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("常见问题");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("cjwt");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("游学游记");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("yxyj");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("营地风采");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("ydfc");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("精彩瞬间");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("jcxj");
        savelist.add(savebean);

        savebean = new BtCustomerNavbarEntity();
        savebean.setName("预约咨询");
        savebean.setCustId(e.getId());
        savebean.setIsHassub("0");
        savebean.setIsDisp("1");
        savebean.setPid(0L);
        savebean.setTypestr("yyzx");
        savelist.add(savebean);
        btCustomerNavbarService.insertOrUpdateBatch(savelist);
    }
}
